<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:if test="admin.adminId==null"><s:text name="admin.add.title"/></s:if><s:else><s:text name="admin.edit.title"/></s:else></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
</head>
<body>
<div id="wrapper">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><s:text name="admin.title"/></div>
	<div class="listtit"><p><span>
	<strong><s:text name="admin.edit.self"/>
	</strong></span></p></div>
	<div id="listoperate" class="listoperate whitebg blinks bbAFC4D3">
		<span class="space20"></span>
		<a href="#" class="current">个人信息修改</a>|
		<a href="#">密码修改</a>
	</div>
	<div class="listadd">
		<s:form id="admin_save" method="post"> 
		<table class="addgrid">
		<tr>
			<th width='200'><s:text name="admin.loginName"/>:</th>
			<td>
			 	<s:property value="admin.loginName"/>
			 	 
			</td>
		</tr>
 
		<tr>
			<th><s:text name="admin.realName"/>:</th>
			<td><s:textfield name="admin.realName"    required="true" requiredposition="right" cssClass="txtin"/>
			<span id="point-realName-Message" style="color: red;">*</span>
			</td>
		</tr>
		<tr>
			<th><s:text name="admin.nickName"/>:</th>
			<td><s:textfield name="admin.nickName" maxlength="18"  required="true" requiredposition="right" cssClass="txtin" />
			<span id="point-nickName-Message" style="color: red;"></span>
			</td>
		</tr>

		<tr>
			<th><s:text name="admin.email"/>:</th>
			<td><s:textfield name="admin.email"    cssClass="txtin" />
				<span id="point-email-Message" style="color: #f00;"></span>
			</td>
		</tr>
		<tr>
			<th><s:text name="admin.mobile"/>:</th>
			<td><s:textfield name="admin.mobile"   cssClass="txtin" maxlength="11"/>
				<span id="point-mobile-Message" style="color: #f00;"></span>
			</td>
		</tr>
		<tr>
			<th><s:text name="admin.telephone"/>:</th>
			<td><s:textfield name="admin.telephone"    cssClass="txtin" maxlength="13" />
				<span id="point-telephone-Message" style="color: #f00;"></span>
				<span id="point-telephone-Message2" style="color:#457d07">(电话格式例如:0571-888888888)</span>
			</td>
		</tr>  
		<tr>
				<th>&nbsp;</th>
				<td><input type="button" value="<s:text name="save"/>" id="submit_input" class="btnlist2" onclick="updateInfo()"/>
					<input type="button" value="取消" id="submit_cancel" class="btnlist2" onclick="javscript:history.back(-1)"/>				
				</td>
		</tr>
		</table>
		<table class="addgrid none">
				<tr>
					<th><s:text name="admin.passwd.old"/>: </th>					 
					<td><s:password name="admin.passwd" maxlength="18" cssClass="txtin" value=""></s:password> 
						<span id="point-passwdold-Message" style="color: #f00;"></span>
					 </td>
				</tr>
				<tr>
					<th><s:text name="admin.passwd.new"/>: </th>
					<td><s:password name="admin.newPasswd"  maxlength="18" cssClass="txtin"></s:password> 
						<span id="point-passwdnew-Message" style="color: #f00;"></span>
					 </td>
				</tr>
				<tr>
					<th><s:text name="admin.passwd.again"/>: </th>
					<td><s:password name="admin.newPasswdAgain"  maxlength="18" cssClass="txtin"></s:password>
						<span id="point-newPasswdAgain-Message" style="color: #f00;"></span>
					  </td>
				</tr>
			<tr>
				<th>&nbsp;</th>
				<td><input type="button" value="<s:text name="save"/>" id="submit_input" class="btnlist2" onclick="updatePwd()"/>
					<input type="button" value="取消" id="submit_cancel" class="btnlist2" onclick="javscript:history.back(-1)"/>				
				</td>
			</tr>
		</table>
		</s:form>
		
		
	</div>
</div>
</body>
</html>
<script type="text/javascript" defer="defer">
 
 
var email_pass    =true;
var mobile_pass   =true;
var telephone_pass=true;  
var passwd_pass=false;
var newPasswd_pass=false;
var newPasswdAgain_pass=false;

	function updateInfo(){ 
		var realName=$("#admin_save_admin_realName").val();
		if($.trim(realName)==""){
			$("#point-realName-Message").html("不能为空！");
			$("#admin_save_admin_realName").focus();
			return false;
		} 
		
		if(email_pass && telephone_pass && mobile_pass){			
			$.ajax({
				async:false,
				url:'${ctx}/system/updatemysef.action?t='+new Date().getTime(),
				data:{
					  'admin.realName':$.trim($("#admin_save_admin_realName").val()),
					  'admin.nickName':$.trim($("#admin_save_admin_nickName").val()),
					  'admin.email':$.trim($("#admin_save_admin_email").val()),
					  'admin.mobile':$.trim($("#admin_save_admin_mobile").val()),
					  'admin.telephone':$.trim($("#admin_save_admin_telephone").val())
				     },
				dataType:'text',
				type:'post',
				success:function(data){
					alert("个人信息修改成功");
				}
			}); 
		}
	}
	function updatePwd(){
		var old=$.trim($("#admin_save_admin_passwd").val());
		if(old==""){
			$$.g("#point-passwdold-Message").style.color="#F00";
			$("#point-passwdold-Message").html("不能为空！");
			$("#admin_save_admin_passwd").focus();
			return false;
		}
		var new_=$.trim($("#admin_save_admin_newPasswd").val());
		if(new_==""){
			$$.g("#point-passwdnew-Message").style.color="#F00";
			$("#point-passwdnew-Message").html("不能为空！");
			$("#admin_save_admin_newPasswd").focus();
			return false;
		}
		var again=$.trim($("#admin_save_admin_newPasswdAgain").val());
		if(again==""){
			$$.g("#point-newPasswdAgain-Message").style.color="#F00";
			$("#point-newPasswdAgain-Message").html("不能为空！");
			$("#admin_save_admin_newPasswdAgain").focus();
			return false;
		}		
		if(new_ != again){
			$$.g("#point-newPasswdAgain-Message").style.color="#F00";
			$("#point-newPasswdAgain-Message").html("两次密码输入不一致！");
			$("#admin_save_admin_newPasswdAgain").focus();
			return false;
		}
		if(passwd_pass && newPasswd_pass  && newPasswdAgain_pass){			
			$.ajax({
				async:false,
				url:'${ctx}/system/updatepdw.action?t='+new Date().getTime(),
				data:{
					  'admin.passwd':$.trim($("#admin_save_admin_passwd").val()),
					  'admin.newPasswd':$.trim($("#admin_save_admin_newPasswd").val()),
					  'admin.newPasswdAgain':$.trim($("#admin_save_admin_newPasswdAgain").val())
				     },
				dataType:'text',
				type:'post',
				success:function(data){
					alert("密码修改成功");
				}
			}); 
			$("#admin_save_admin_newPasswdAgain").val('');
			$("#admin_save_admin_newPasswd").val('');
			$("#admin_save_admin_passwd").val('');
			$("#point-newPasswdAgain-Message").html('');
			$("#point-passwdnew-Message").html('');
			$("#point-passwdold-Message").html('');
			
		}

		
	}
	
	var pwdReg =/^[a-zA-Z0-9][a-zA-Z0-9]{5,17}$/;
	
	$$.addEvent("#admin_save_admin_passwd","blur",function(){
		var passwd=$("#admin_save_admin_passwd").val();
		if(passwd==""){
			passwd_pass=true;
		}else{			 
			if(!pwdReg.test(passwd)){
				$$.g("#point-passwdold-Message").style.color="#F00";
				$$.g("#point-passwdold-Message").innerHTML = "密码格式错误";
				passwd_pass=false;
			}else{
				$$.g("#point-passwdold-Message").style.color="#0f0";
				$$.g("#point-passwdold-Message").innerHTML = "成功";
				passwd_pass=true;
			}
		}
	});
	
	$$.addEvent("#admin_save_admin_newPasswd","blur",function(){
		var newPasswd=$("#admin_save_admin_newPasswd").val();
		if(newPasswd==""){
			newPasswd_pass=true;
		}else{
			if(!pwdReg.test(newPasswd)){
				$$.g("#point-passwdnew-Message").style.color="#F00";
				$$.g("#point-passwdnew-Message").innerHTML = "密码格式错误";
				newPasswd_pass=false;
			}else{
				$$.g("#point-passwdnew-Message").style.color="#0f0";
				$$.g("#point-passwdnew-Message").innerHTML = "成功";
				newPasswd_pass=true;
			}
		}
	});
	
	$$.addEvent("#admin_save_admin_newPasswdAgain","blur",function(){
		var newPasswdAgain=$("#admin_save_admin_newPasswdAgain").val();
		if(newPasswdAgain==""){
			newPasswdAgain_pass=true;
		}else{
			if(!pwdReg.test(newPasswdAgain)){
				$$.g("#point-newPasswdAgain-Message").style.color="#F00";
				$$.g("#point-newPasswdAgain-Message").innerHTML = "密码格式错误";
				newPasswdAgain_pass=false;
			}else{
				$$.g("#point-newPasswdAgain-Message").style.color="#0f0";
				$$.g("#point-newPasswdAgain-Message").innerHTML = "成功";
				newPasswdAgain_pass=true;
			}
		}
	});
 
	$$.addEvent("#admin_save_admin_email","blur",function(){
		var email=$("#admin_save_admin_email").val();
		if(email==""){
			email_pass=true;
		}else{
			if(!$$.email(email)){
				$$.g("#point-email-Message").style.color="#F00";
				$$.g("#point-email-Message").innerHTML = "邮件格式错误";
				email_pass=false;
			}else{
				$$.g("#point-email-Message").style.color="#0f0";
				$$.g("#point-email-Message").innerHTML = "成功";
				email_pass=true;
			}
		}
	});
	
	$$.addEvent("#admin_save_admin_mobile","blur",function(){
		var mobile=$("#admin_save_admin_mobile").val();
		if(mobile==""){
			mobile_pass=true;
		}else{
			if(!$$.mobile(mobile)){
				$$.g("#point-mobile-Message").style.color="#F00";
				$$.g("#point-mobile-Message").innerHTML = "手机格式错误";
				mobile_pass=false;
			}else{
				$$.g("#point-mobile-Message").style.color="#0f0";
				$$.g("#point-mobile-Message").innerHTML = "成功";
				mobile_pass=true;
			}
		}
	});
	
    $$.addEvent("#admin_save_admin_telephone","blur",function(){
    	var tel=$("#admin_save_admin_telephone").val();
    	if(tel==""){
    		telephone_pass=true;
    	}else{
    		var telephoneReg= /^\d{3}-\d{7}|\d{3}-\d{8}|\d{4}-\d{7}|\d{4}-\d{8}$/;
    		if(!telephoneReg.test(tel) ){
    			$$.g("#point-telephone-Message").style.color="#F00";
    			$$.g("#point-telephone-Message").innerHTML = "请输入正确的电话格式，例如:0571-888888888";
    			$$.g("#point-telephone-Message2").style.display="none"; 
    			telephone_pass=false;
    		}else{
    			$$.g("#point-telephone-Message").style.color="#0f0";
    			$$.g("#point-telephone-Message").innerHTML = "成功";
    			$$.g("#point-telephone-Message2").style.display="none"; 
    			telephone_pass=true;
    		}
    	}
	});  
    $$.tab("#listoperate a",".listadd table","click");
</script>